// pages/login/login.js
const app = getApp()
const $ = app.globalData
Page({
	tips_primary: false,
	tips_primary_disabled: 0,
	/**
	 * 页面的初始数据
	 */
	data: {
		focus: {
			A: false,
			B: false,
			C: false,
			D: false,
			E: false
		},
		input: {
			A: false,
			B: false,
			C: false,
			D: false,
			E: false
		},
		thistext: "验证码已下发，请注意查收",
		errortext: "请输入信息",
	},
	bindBlur: function(e) {
		this.setData({
			keyboard: 0,
			["focus." + e.target.id]: false,
			["input." + e.target.id]: e.detail.value
		});
		console.log("键盘输入内容：" + e.detail.value);
	},
	bindFocus: function(e) {
		if (e.currentTarget.id) {
			wx.pageScrollTo({
				scrollTop: e.currentTarget.id > "B" ? 270 : 140
			});
			this.setData({
				["focus." + e.currentTarget.id]: true
			});
		}
	},
	// 发送验证码
	bindShowTopTips: function(e) {
		var a = this.data
		var that = this
		if (a.input['B'] == "" || a.input['B'][0] != "1" || a.input['B'].length != 11) {
			that.setData({
				tips_warn: true,
				errortext: "请输入正确的手机号"
			})
			setTimeout(function() {
				that.setData({
					tips_warn: false
				})
			}, 3000);
		} else {
			$.sendMessage(a.input['B'])
			this.setData({
				tips_primary: true
			});
			setTimeout(() => {
				this.setData({
					tips_primary: false
				});
			}, 3000);
			var timestamp = Date.parse(new Date()) / 1000 + 60;
			this.setData({
				tips_primary_disabled: 60
			});
			var interval = setInterval(() => {
				if (timestamp >= Date.parse(new Date()) / 1000) {
					this.setData({
						tips_primary_disabled: timestamp - Date.parse(new Date()) / 1000
					});
				} else {
					this.setData({
						tips_primary_disabled: 0
					});
					clearInterval(interval);
					return true;
				}
			}, 1000);
		}
	},
	
	// 确认
	forgot:function(){
		var that = this
		wx.showLoading({title:'信息获取中'})
		setTimeout(function() {
			wx.hideLoading();
			var input = that.data.input
			wx.showLoading({title: '信息确认中'})
			wx.request({
				url:$.AdminUrl+"/YApi/forgetPwd",
				data:{
					loginname:input['A'],
					phone:input['B'],
					smscode:input['C'],
					password:input['D'],
				},
				success:function (data) {
					wx.hideLoading();
					wx.showModal({
						icon:'none',
						title:data.data.code?'修改成功':'修改失败',
						content:data.data.msg
					})
				}
			})
		}, 1000);
		
	},
	// 分享转发
	onShareAppMessage: function() {
		var userinfo = wx.getStorageSync('userinfo')
		return {
			title: '优悦购生活管家',
			path: '/pages/index/index?userid=' + userinfo.loginname,
			success: (res) => {
				console.log("转发成功", res);
			},
			fail: (res) => {
				console.log("转发失败", res);
			}
		}
	}
})
